const xingzuoman = [
    ['baiyang', '0321', '0420'],
    ['jinniu', '0421', '0521'],
    ['shuangzi', '0522', '0621'],
    ['juxie', '0622', '0723'],
    ['shizi', '0724', '0823'],
    ['chunv', '0824', '0923'],
    ['tiancheng', '0924', '1023'],
    ['tianxie', '1024', '1122'],
    ['sheshou', '1123', '1221'],
    ['mojie', '1222', '1231'],
    ['mojie', '0101', '0120'],
    ['shuiping', '0121', '0219'],
    ['shuangyu', '0220', '0320']
];

function formatAgeOrXingZuoData(accountList, age, birthday) {
    let accountInfo = null;
    if (Object.keys(accountList)[0].split('~').length < 2) {
        const name = getXingZuoName(birthday);
        accountInfo = accountList[name];
    } else {
        Object.keys(accountList).forEach((ageArrage) => {
            const minAge = ageArrage.split('~')[0];
            const maxAge = ageArrage.split('~')[1];
            if (age >= minAge && age <= maxAge) {
                accountInfo = accountList[ageArrage];
            }
        });
    }
    return accountInfo;
}

function getXingZuoName(birthday) {
    let name = null;
    xingzuoman.forEach((item) => {
        if (birthday >= item[1] && birthday <= item[2]) {
            name = item[0];
        }
    });
    return name;
}

export { formatAgeOrXingZuoData };
